// app.js
import {
  STATUS_BAR_HEIGHT,
  MENU_BUTTON_HEIGHT,
  NAVIGATION_BAR_HEIGHT
} from './constant/constant'
App({
  onLaunch() {
    //自定义navigationBar需要的高度参数
    let statusBarHeight=0
    let platform='android'
    wx.getSystemInfoAsync()
    wx.getSystemInfoAsync({
      success: (result) => {
        console.log(result)
        if(result){
          if(result.statusBarHeight){
            statusBarHeight=result.statusBarHeight
            wx.setStorageSync(STATUS_BAR_HEIGHT, statusBarHeight)
          }
          if(result.platform){
            platform=result.platform
          }
          const {top,bottom,height} = result.safeArea
          let temp = result.windowHeight-(bottom-height)
          console.log("temp",top,bottom,height,result.windowHeight,temp)
          this.globalData.screenHeight=result.screenHeight
          this.globalData.windowHeight=result.windowHeight
          this.globalData.safeWindowHeight = temp//兼容iphoneX及以上系列，底部黑色条不是安全区域

        }
      },
    })
    const {
      top,
      height
    } = wx.getMenuButtonBoundingClientRect()
    wx.setStorageSync(MENU_BUTTON_HEIGHT, height ? height : 32)
    if (top && top != 0 && height && height != 0) {
      let navigationBarHeight = (top - statusBarHeight) * 2 + height
      wx.setStorageSync(NAVIGATION_BAR_HEIGHT, navigationBarHeight)
    }else{
      wx.setStorageSync(NAVIGATION_BAR_HEIGHT, platform==='android'?48:40)
    }
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    var hasSplash = wx.getStorageSync("hasSplash")
    // if(hasSplash){
    //   wx.switchTab({
    //     url: 'pages/main/main',
    //   })
    // }else{
    //   wx.redirectTo({
    //     url: 'pages/splash/splash',
    //   })
    // }
    wx.redirectTo({
      url: 'pages/splash/splash',
    })

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null,
    windowHeight:0,
    screenHeight:0,
    safeWindowHeight:0,
    hasLogined:false
  }
})